BASE = key_test
ELF_TARGET = $(BASE).elf
BIN_TARGET = $(BASE).bin
SRCS = key_test.c
OBJS = ${SRCS:.c=.o}

TC_PREFIX=arm-eabi-
CC=${TC_PREFIX}gcc
LD=${TC_PREFIX}ld
OBJDUMP=${TC_PREFIX}objdump
OBJCOPY=${TC_PREFIX}objcopy
READELF=${TC_PREFIX}readelf
NM=${TC_PREFIX}nm

CFLAGS= -Wall -Wstrict-prototypes -Wno-trigraphs -pipe -march=armv4t -mtune=arm920t
LDFLAGS= -N -p -X -T${BASE}.lds

.PHONY: all clean extra

all:: ${ELF_TARGET}

extra: all
	${OBJDUMP} -xS ${ELF_TARGET} > ${BASE}.asm
	${READELF} -a ${ELF_TARGET} > ${BASE}.r
	${NM} ${ELF_TARGET} > ${BASE}.n

${ELF_TARGET}: start.o ${OBJS} 
	${LD} ${LDFLAGS} -o $@ $^
	${OBJCOPY} -O binary ${ELF_TARGET} ${BIN_TARGET}

${OBJS}: %.o: %.c
	${CC} ${CFLAGS} -o $@ -c $< 

start.o: start.S
	${CC} ${CFLAGS} -o $@ -c $< 

clean:
	-rm -f *~ *.o ${ELF_TARGET} ${BASE}.asm ${BASE}.r ${BASE}.n ${BIN_TARGET}

